package com.wyzz.hr.action;

import java.lang.reflect.Method;
import java.math.BigDecimal;
import java.util.List;

import com.wyzz.hr.base.BaseAction;
import com.wyzz.hr.base.Status;
import com.wyzz.hr.bo.IEmpSalaryAcctitemsBo;
import com.wyzz.hr.bo.ISalaryconfBo;
import com.wyzz.hr.pojo.Employee;
import com.wyzz.hr.pojo.Empsalaryacctitems;
import com.wyzz.hr.pojo.Empsalaryconfig;
import com.wyzz.hr.spring.SpringBeanFactory;

public class ViewDetail extends BaseAction implements Status {

	public ViewDetail() {
	}

	public String execute() throws Exception {
		paramString = "searchSalary";
		if (detailid == null) {
			detailid = getCurrentEmpNo();
			paramString = "mySalaryConf";
		}
		ISalaryconfBo salaryBo = (ISalaryconfBo) getBean("salaryconfBo");
		empWithSalaryInfo = salaryBo.findConfigByEmpId(detailid);
		if (empWithSalaryInfo == null) {
			addErrorInfo("\u5BF9\u4E0D\u8D77\uFF0C\u60A8\u8981\u67E5\u770B\u7684\u5458\u5DE5\u4E0D\u5B58\u5728\uFF01");
			return "error";
		}
		Empsalaryconfig salaryconfig = empWithSalaryInfo.getConfig();
		if (salaryconfig == null) {
			addErrorInfo("\u5BF9\u4E0D\u8D77\uFF0C\u60A8\u8981\u67E5\u770B\u7684\u5458\u5DE5\u6CA1\u6709\u914D\u7F6E\u85AA\u8D44\uFF01");
			return "error";
		}
		salaryconfig.decryEmpSalaryConf(salaryconfig);
		IEmpSalaryAcctitemsBo empSalaryAcctitemsBo = (IEmpSalaryAcctitemsBo) SpringBeanFactory
				.getBean("empsalaryacctitemsBo");
		acctItems = empSalaryAcctitemsBo.getItemsByAcctversion(salaryconfig
				.getEscEsavId().getId());
		int size = acctItems.size();
		for (int i = 0; i < size; i++) {
			Empsalaryacctitems item = (Empsalaryacctitems) acctItems.get(i);
			Class ownerClass = salaryconfig.getClass();
			Method method = ownerClass.getMethod((new StringBuilder()).append(
					"getEscColumn").append(i + 1).toString(), new Class[0]);
			Object object = method.invoke(salaryconfig, new Object[0]);
			item.setItemValue((BigDecimal) object);
		}

		return "success";
	}

	public String getDetailid() {
		return detailid;
	}

	public void setDetailid(String detailid) {
		this.detailid = detailid;
	}

	public Employee getEmpWithSalaryInfo() {
		return empWithSalaryInfo;
	}

	public void setEmpWithSalaryInfo(Employee empWithSalaryInfo) {
		this.empWithSalaryInfo = empWithSalaryInfo;
	}

	public List getAcctItems() {
		return acctItems;
	}

	public void setAcctItems(List acctItems) {
		this.acctItems = acctItems;
	}

	public String getParamString() {
		return paramString;
	}

	public void setParamString(String paramString) {
		this.paramString = paramString;
	}

	private Employee empWithSalaryInfo;
	private String detailid;
	List acctItems;
	private String paramString;
}
